package initialize

import (
	"fmt"
	"gitee.com/layheart/gameServer/global"
	"gorm.io/driver/mysql"
	"gorm.io/gorm"
)

func Mysql() {

	dsn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local",
		global.CONFIG.Mysql.Username,
		global.CONFIG.Mysql.Password,
		global.CONFIG.Mysql.Path,
		global.CONFIG.Mysql.Port,
		global.CONFIG.Mysql.Database,
	)

	var err error
	global.Mysql, err = gorm.Open(mysql.Open(dsn), &gorm.Config{})
	if err != nil {
		panic("mysql connection error:" + err.Error())
	}
}
